package org.sipsl.gisystems.gentest.rte.commands;

import java.io.BufferedWriter;
import java.io.FileWriter;

import org.sipsl.gisystems.gentest.rte.util.DataParams;
import org.sipsl.gisystems.gentest.rte.util.GenericUtil;
import org.sipsl.gisystems.gentest.rte.util.Params;
import org.sipsl.gisystems.gentest.rte.util.VoiceMoParams;

public class SetMoVoice extends RteCommand {

	private int duration;
	private int callingZone;
	
	public SetMoVoice(VoiceMoParams p, int duration, int callingZone) {
		super(p);
		this.duration = duration;
		this.callingZone = callingZone;
		// TODO Auto-generated constructor stub
	}

	@Override
	public String getScript() {
		// TODO Auto-generated method stub
		return"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_initial:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_update:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_term:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n";
	}

	@Override
	public void dumpScript(String title, int i) {
		try  
		{
			String prefix = GenericUtil.MakePrefix(i);
		
		    FileWriter fstream = new FileWriter(title+"/"+prefix+":movoice-New.hpi"); //true tells to append data.
		    BufferedWriter out = new BufferedWriter(fstream);
		    GenericUtil.LOG(title+"/"+prefix+":movoice-New.hpi");
		    GenericUtil.LOG("MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_initial:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		    		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_update:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,16:stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		    		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_term:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n",0,0);
		    out.write("MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_initial:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		    		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_update:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n"+
		    		"MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_term:clgparty,\"tel:+"+p.getMSISDN()+";noa="+p.getNOA()+";imsi="+p.getIMSI()+"\":cldparty,\"tel:+"+p.getBMSISDN()+";noa="+p.getBNOA()+";imsi="+p.getBIMSI()+"\":session_id,TMP_SESSION_ID:ratinggrp,"+callingZone+":stp,"+((VoiceMoParams)p).getSTP()+":vlr,"+((VoiceMoParams)p).getVLR()+":cctime,"+duration+":SUBID,"+p.getMSISDN()+";\n");
		    out.flush();
		    out.close();
		    
		    testDescription = "Make a voice call with subscriber " + p.getMSISDN() + 
		    		" and IMSI " + p.getIMSI() + 
    				" to number " + p.getBMSISDN() +
    				" from VLR " + ((VoiceMoParams)p).getVLR() +
    				" and STP " +  ((VoiceMoParams)p).getSTP() +
    				" duration in secs " + duration;
		}
		catch (Exception e)
		{
		    System.err.println("Error: " + e.getMessage());
		}

	}

}
//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_initial:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+32665;noa=2;imsi=":session_id,TMP_S
//ESSION_ID:ratinggrp,16:stp,447785000685:vlr,447785000685:cctime,3601:SUBID,447300030202;
//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_update:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+32665;noa=2;imsi=":session_id,TMP_SE
//SSION_ID:ratinggrp,16:stp,447785000685:vlr,447785000685:cctime,3601:SUBID,447300030202;
//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_term:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+32665;noa=2;imsi=":session_id,TMP_SESS
//ION_ID:ratinggrp,16:stp,447785000685:vlr,447785000685:cctime,3601:SUBID,447300030202;

//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_initial:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+421949240941;noa=4;imsi=":session_id,TMP_SESSION_ID:ratinggrp,17:stp,35383:vlr,35383:cctime,600:SUBID,447300030202;
//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_update:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+421949240941;noa=4;imsi=":session_id,TMP_SESSION_ID:ratinggrp,17:stp,35383:vlr,35383:cctime,600:SUBID,447300030202;
//MOD:ELEMENT,RTE_DIAMGW:DIAMTEMPLATE,rte_mo_voice_term:clgparty,"tel:+447300030202;noa=4;imsi=2341592200":cldparty,"tel:+421949240941;noa=4;imsi=":session_id,TMP_SESSION_ID:ratinggrp,17:stp,35383:vlr,35383:cctime,600:SUBID,447300030202;